﻿using System;
using System.Runtime.Serialization;

namespace IntoNails.Models
{
    public enum Title
    {
        Mr,
        Mrs,
        Miss,
        Ms,
        Dr,
        Sir
    }

    public enum SendAppointmentType
    {
        None,
        SMS,
        Email,
        Both
    }

    [Serializable]
    public class Customer : Person, ISerializable
    {
        #region Fields

        private string _smsTextNumber;

        private bool _donotSendPromotionalEmail;
        private bool _donotSendPostalMail;
        private bool _donotCallByPhone;

        private SendAppointmentType _sendAppointmentType;

        #endregion

        #region Constructors

        protected Customer()
        {
        }

        public Customer(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.SmsTextNumber = info.GetString("SmsTextNumber");
            this.DonotSendPromotionalEmail = info.GetBoolean("DonotSendPromotionalEmail");
            this.DonotSendPostalMail = info.GetBoolean("DonotSendPostalMail");
            this.DonotCallByPhone = info.GetBoolean("DonotCallByPhone");
            this.SendAppointmentBy = (SendAppointmentType)info.GetValue("SendAppointmentBy", typeof(SendAppointmentType));
        }

        #endregion

        #region Properties

        public string SmsTextNumber
        {
            get { return this._smsTextNumber; }
            set
            {
                this._smsTextNumber = value;
                base.RaisePropertyChanged("SmsTextNumber");
            }
        }

        public bool DonotSendPromotionalEmail
        {
            get { return this._donotSendPromotionalEmail; }
            set
            {
                this._donotSendPromotionalEmail = value;
                base.RaisePropertyChanged("DonotSendPromotionalEmail");
            }
        }

        public bool DonotSendPostalMail
        {
            get { return this._donotSendPostalMail; }
            set
            {
                this._donotSendPostalMail = value;
                base.RaisePropertyChanged("DonotSendPostalMail");
            }
        }

        public bool DonotCallByPhone
        {
            get { return this._donotCallByPhone; }
            set
            {
                this._donotCallByPhone = value;
                base.RaisePropertyChanged("DonotCallByPhone");
            }
        }

        public SendAppointmentType SendAppointmentBy
        {
            get { return this._sendAppointmentType; }
            set
            {
                this._sendAppointmentType = value;
                base.RaisePropertyChanged("SendAppointmentBy");
            }
        }

        #endregion

        public static Customer CreateWalkInCustomer()
        {
            return new Customer()
                       {
                           UniqueCode = Guid.NewGuid(),
                           DisplayName = "Walk In",
                           SendAppointmentBy = SendAppointmentType.None,
                           CreatedDate = DateTime.Now,
                           UpdatedDate = DateTime.Now,
                           IsValid = true
                       };
        }

        public static Customer CreateNewCustomer()
        {
            return new Customer
            {
                UniqueCode = Guid.NewGuid(),
                DisplayName = string.Empty,
                SendAppointmentBy = SendAppointmentType.Both,
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now,
                IsValid = true
            };
        }

        #region Implementation of ISerializable

        public new void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            info.AddValue("SmsTextNumber", this.SmsTextNumber);
            info.AddValue("DonotSendPromotionalEmail", this.DonotSendPromotionalEmail);
            info.AddValue("DonotSendPostalMail", this.DonotSendPostalMail);
            info.AddValue("DonotCallByPhone", this.DonotCallByPhone);
            info.AddValue("SendAppointmentBy", this.SendAppointmentBy);
        }

        #endregion

        #region Object Overriden

        public override string ToString()
        {
            return string.Format("Custome ID: {0} | Name: {1} {2} {3}", this.UniqueCode, this.FirstName, this.MiddleName, this.LastName);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            Customer other = obj as Customer;
            if (other == null)
            {
                return false;
            }

            return this.UniqueCode == other.UniqueCode;
        }

        #endregion
    }
}
